<%@ page import= "modelo.Funcionario" %>
<%@ page import= "modelo.Departamento" %>
<%@ page import= "java.util.Vector" %>
<html> <head></head> 
  <body>
 
    <form action = "ControlaEmpresa" method = "get">
    <%  Vector func;
        Vector depto;
	    func = (Vector) request.getSession().getAttribute("Empresa01");
	    depto = (Vector) request.getSession().getAttribute("Depto01");
        String indice = request.getParameter("registro");
	    String operacao = request.getParameter("operacao"); 	
        Funcionario f = new Funcionario();
            
      if (operacao.equals("1")) {
    		f.setNome("");
 	} else {
         	int ind = Integer.parseInt(indice);
         	f = (Funcionario)func.get(ind);
 	}
   %>
  <table border="1" width="50%">
    <tr>
       <th COLSPAN="2"> DADOS DO FUNCIONARIO </th>
    </tr>
    <tr>
      <td>Nome Funcionario: </td>
      <td><input name="txtNomeFunc" value="<%=f.getNome()%>" size="30"></td>
    </tr>
    <tr>
      <td>Salario: </td>
      <td><input name="txtSalario"  value="<%= f.getSalario() %>" size="10"> </td>
    </tr>
    <tr>
      <td>Sexo: </td>
      <td>
      	  <%
      	  	boolean sex = f.getSexo();
      	  	if ( sex ) {
      	  		out.write("<input type=\"radio\" name=\"radSexo\" value=\"true\" checked>Masculino<br>");
      	  	    out.write("<input type=\"radio\" name=\"radSexo\" value=\"false\">Feminino" );
      	  	} else {
      	  		out.write("<input type=\"radio\" name=\"radSexo\" value=\"true\" >Masculino<br>");
  	  	    	out.write("<input type=\"radio\" name=\"radSexo\" value=\"false\" checked>Feminino" );
      	  	}
      	  %>
      </td>
    </tr>
    
    <tr> <td>Departamento: </td>
         <%  if (operacao.equals("1")) {
            out.write("<td>");
        	out.write("<select name=\"txtDepto\">");
        	for ( int i = 0 ; i < depto.size() ; i++ ) {
        		Departamento d = (Departamento)depto.get(i);
        		out.write("<option value=\""+ d.getId() + "\">" + d.getDepto() +"</option>");
        	} 
        	out.write("</select>");
        	out.write("</td>");
        	}    
         else { 
        	 out.write("<td>");
        	 out.write("<select name=\"txtDepto\">");
        	 for ( int i = 0 ; i < depto.size() ; i++ ) {
         		Departamento d = (Departamento)depto.get(i);
         		if ( f.getDepto().equals( d.getDepto() ) ){
         		    out.write("<option value=\""+ d.getId() + "\" selected>" + d.getDepto() +"</option>");
         		} else {
         			out.write("<option value=\""+ d.getId() + "\">" + d.getDepto() +"</option>");
         		}
         	 } 
        	 
        	 out.write("</select>");
        	 out.write("</td>");
          } %> 
    </tr> 
  </table>
      <input type="hidden" name="txtMatricula" value="<%= f.getMatricula() %>" >
      <br>
      <%
        	if (operacao.equals("1")) {
      %> 
                <input type="submit" value="Incluir Funcionario" onclick="this.form.operacao.value=3">

          <%  } else {   %>
                <input type="submit" value="Alterar Funcionario" onclick="this.form.operacao.value=4" >
                <input type="submit" value="Excluir Funcionario" onclick="this.form.operacao.value=5" >
        <%  }   %>

	<input type="hidden" name="operacao"  value ="" >
        	<input type="hidden" name="registro"  value = <%=indice%> >           
    </form>
    <p>  <h3>Retornar para a lista de Funcionarios  
		<a href="ControlaEmpresa?operacao=0">clique aqui</a></h3>

 </body> 
</html> 
      